package demo02;

import java.io.*;
import java.util.Objects;

public class Test01 {

    public static final String PATH = Objects.requireNonNull(Test01.class.getClassLoader().getResource("aaaa.txt")).getPath();

    public static void main(String[] args) {
        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(PATH));
             BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("D:\\bbb.txt"))) {
            byte[] myByte = new byte[1];
            int length;
            while ((length = bufferedInputStream.read(myByte)) != -1) {
                bufferedOutputStream.write(myByte, 0, length);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test05() {
        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream(PATH));
             BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(new FileOutputStream("D:\\bbb.txt"))) {
            int b;
            while ((b = bufferedInputStream.read()) != -1) {
                bufferedOutputStream.write(b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test04() {
        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("D:\\SnailsCode\\BackEnd\\JavaLearn2\\Day15\\src\\main\\resources\\aaaa.txt"))) {
            byte[] myByte = new byte[3];
            int length;
            while ((length = bufferedInputStream.read(myByte)) != -1) {
                System.out.println(new String(myByte, 0, length));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test03() {
        try (BufferedInputStream bufferedInputStream = new BufferedInputStream(new FileInputStream("D:\\SnailsCode\\BackEnd\\JavaLearn2\\Day15\\src\\main\\resources\\aaaa.txt"))) {
            int b;
            while ((b = bufferedInputStream.read()) != -1) {
                System.out.print((char) b);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test02() {
        try (FileInputStream fileInputStream = new FileInputStream("D:\\SnailsCode\\BackEnd\\JavaLearn2\\Day15\\src\\main\\resources\\aaaa.txt")) {
            byte[] myByte = new byte[3];
            int length = -1;
            while ((length = fileInputStream.read(myByte)) != -1) {
                System.out.print(new String(myByte, 0, length));
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    private static void test01() {
        try (FileInputStream fileInputStream = new FileInputStream("D:\\SnailsCode\\BackEnd\\JavaLearn2\\Day15\\src\\main\\resources\\aaaa.txt")) {
            int b;
            while ((b = fileInputStream.read()) != -1) {
                System.out.print((char) b);
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
